package com.dcd.controller;

import com.dcd.pojo.Information;
import com.dcd.service.InformationService;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/InformationController")
public class InformationController {
    @Autowired(required = false)
    private InformationService is;

    /**
     * 查询所有视频
     *
     * @param pageZiXunIndex 当前页数
     * @return 以map返回所有资讯
     */
    @RequestMapping("/Information_all")
    public Map<String, Object> Information_all(@RequestParam Integer pageZiXunIndex) {
        return is.selInformation(pageZiXunIndex);
    }

    /**
     * 根据资讯id查询单个资讯详情
     *
     * @param information_id 资讯id
     * @return 返回根据资讯id查询出来的一个对象
     */
    @RequestMapping("/singleInformation")
    public Information singleInformation(@RequestParam Integer information_id) {
        return is.singleInformation(information_id);
    }

    /**
     * @return 以list返回只查询前十的热搜榜
     */
    @RequestMapping("/tenInfoAll")
    public List<Information> tenInfoAll() {
        return is.tenInfoAll();
    }

    /**
     * 查询首页最新的24条资讯
     *
     * @return 返回最新的24条资讯
     */
    @RequestMapping("/select_index_information")
    public List<Information> select_index_information() {
        return is.select_index_information();
    }

    /**
     * 根据车系id查询此系列的所有资讯
     *
     * @param car_series_id 获取车系id
     * @return 返回同车系所有资讯
     */
    @RequestMapping("/seleCarSeriesInformation")
    public List<Information> seleCarSeriesInformation(@RequestParam Integer car_series_id) {
        return is.seleCarSeriesInformation(car_series_id);
    }

    /**
     * 搜索查询资讯
     *
     * @param solr_content 搜索文本内容
     * @param page_index   当前页数
     * @return
     */
    @RequestMapping("/select_information_by_solr")
    public Map<String, Object> select_information_by_solr(@RequestParam String solr_content, @RequestParam int page_index) throws IOException, SolrServerException {
        return is.select_information_by_solr(solr_content, page_index);
    }
    /**
     * 查询最近一周的最新资讯
     * @return
     */
    @RequestMapping("/select_week")
    public List<Information> select_week(){
        return is.select_week();
    }

}
